package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.url.Url;

import java.util.List;

/**
 * Created by Administrator on 2017/3/22.
 */

public class GridOrderAdapter extends BaseAdapter {
    private Context context;
    private List<String> list;

    public GridOrderAdapter(Context context, List<String> imgList) {
        this.context = context;
        this.list = imgList;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(null==convertView){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_img, parent, false);
            holder.ivImg = (ImageView) convertView.findViewById(R.id.ivImg);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        if(null!=list.get(position)&&!"".equals(list.get(position))){
            Glide.with(context).load(Url.IMG_URL+list.get(position)).placeholder(R.mipmap.iv_eg).fitCenter().into(holder.ivImg);
        }
        return convertView;
    }

    class ViewHolder{
        private ImageView ivImg;
    }
}
